<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/27 0027
 * Time: 下午 8:00
 */
namespace app\common\model;

use think\Model;

class Product extends BaseModel{
    protected $resultSetType = 'collection';

    const SPEC_CLASS_1 =1;//1单规格 2多规格
    const SPEC_CLASS_2 =2;

    /**
     * @param $productIds
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 根据商品id组合查询出商品集合信息
     */
    public function getProductList($productIds){
        return self::where('id','in',$productIds)->select();
    }

    /**
     * @return \think\model\relation\HasOne
     * 获取商品店铺关联
     */
    public function getStoreProduct()
    {
        return $this->hasOne('storeproduct','product_id','id');
    }

    public function productdetail(){
        return $this->hasOne('Productdetail','productId','id');
    }



//belongsToMany('关联模型名','中间表名','外键名','当前模型关联键名',['模型别名定义']);
//5.0.8+版本开始，中间表名无需添加表前缀，并支持定义中间表模型，例如：

    public function Storeproduct()
    {
        return $this->belongsToMany('Store','Storeproduct');
    }



    public function getProduct($param){
       return self::where('id','=',$param->productId)->find();
    }



}